import request from '@/utils/request'

export const getAddressListApi = () => {
  return request.get('/address/list')
}

export const setDefaultAddressApi = (addressId) => {
  return request({
    url: '/address/setDefault',
    method: 'post',
    data: {
      addressId
    }
  })
}

export const editAddressApi = (obj) => {
  return request({
    url: '/address/edit',
    method: 'post',
    data: {
      addressId: obj.address_id,
      form: {
        name: obj.name,
        phone: obj.phone,
        region: [{
          label: '上海',
          value: 782
        },
        {
          label: '上海市',
          value: 783
        },
        {
          label: '徐汇区',
          value: 785
        }],
        detail: '北京路1号楼8888室'
      }
    }
  })
}

export const defaultAddressIdApi = () => {
  return request.get('/address/defaultId')
}

export const getDefaultAddressApi = (id) => {
  return request({
    url: '/address/detail',
    params: { addressId: id }
  })
}

export const addAddressApi = (obj) => {
  return request({
    url: '/address/add',
    method: 'post',
    data: {
      form: {
        name: obj.name,
        phone: obj.phone,
        region: [{
          label: '上海',
          value: 782
        },
        {
          label: '上海市',
          value: 783
        },
        {
          label: '徐汇区',
          value: 785
        }],
        detail: '北京路1号楼8888室'
      }
    }
  })
}
